package com.demo.arch.datapulsedemo.v1_simple_direct.controller;

import com.demo.arch.datapulsedemo.common.TaskResult;
import com.demo.arch.datapulsedemo.v1_simple_direct.task.SimpleReportTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * V1版本报表控制器
 * 
 * @author DataPulse Team
 */
@Slf4j
@RestController
@RequestMapping("/v1")
public class ReportController {

  @Autowired
  private SimpleReportTask reportTask;

  /**
   * 执行报表任务
   * 
   * 测试URL:
   * - 日报: http://localhost:8080/v1/report?type=日报
   * - 周报: http://localhost:8080/v1/report?type=周报
   * - 月报: http://localhost:8080/v1/report?type=月报
   */
  @GetMapping("/report")
  public TaskResult generateReport(@RequestParam(defaultValue = "日报") String type) {
    log.info("=== 收到V1报表生成请求 ===");
    log.info("请求参数 - 报表类型: {}", type);

    TaskResult result = reportTask.execute(type);

    log.info("=== V1报表任务执行结果: {} ===", result.isSuccess() ? "成功" : "失败");
    return result;
  }

  /**
   * 健康检查接口
   */
  @GetMapping("/health")
  public TaskResult health() {
    return TaskResult.success("V1服务正常运行");
  }
}
